target = script.vars[0]
room = nil

if target.start_with?('-r')
  a, room, target = target.split(' ', 3)
  room = room.to_i
end

cr = Room.current.db_id
until ['hunt','path','area','here'].include?(h = hunt_target(target)) do
  (wait_until {Char.enemy.empty?};next) if h == "fighting"
  put h
  wait_until(3) {Room.current.db_id != cr}
  break if room == Room.current.db_id
  cr = Room.current.db_id
end